package com.bjsxt.shopcenter.back.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.bjsxt.shopcenter.common.controller.BaseController;
import com.bjsxt.shopcenter.common.util.ConstatFinalUtil;
import com.bjsxt.shopcenter.users.pojo.AAdmins;

/**
 * 管理员登录后访问的页面
 * @author FanXiaokang
 *
 */
@Controller
@RequestMapping("/back/admins")
public class AdminsBackController extends BaseController
{
	@RequestMapping("/main")
	public String main()
	{
		ConstatFinalUtil.LOGGER.info("---- main ----");
		return "/back/main";
	}
	
	/**
	 * 退出
	 * @param request
	 * @param response
	 * @param session
	 * @return
	 * @throws IOException 
	 */
	@RequestMapping("/logout")
	public String logout(HttpServletRequest request,HttpServletResponse response,HttpSession session) throws IOException
	{
		AAdmins admins = (AAdmins) session.getAttribute("admins");
		/* 处理当前服务的session*/
		session.removeAttribute("admins");
		/*
		 * 还要操作用户中心
		 * 如何让客户端跳转到用户中心退出的url
		 * 如何在用户中心操作token
		 */
		/* 跳转到用户中心的登录页面，并且将returnUrl带上去*/
		String usersCenterLogoutUrl = ConstatFinalUtil.BUNDLE.getString("users.center.logoutUrl") + "&token=" + admins.getToken();
		ConstatFinalUtil.LOGGER.info("--usersCenterLogoutUrl:{}",usersCenterLogoutUrl);
		/* 客户端跳转*/
		response.sendRedirect(usersCenterLogoutUrl);
		return null;
	}
}
